x = int(input())
x1=x
d = x1%10
c = x1//10%10
b = x1//100%10
a = x1//1000%10
max_prost = 0
k1 = b * 100 + c * 10 + d
c1= k1
count = 0
for i in range( 1 , c1+ 1):
    if c1 % i == 0:
      count += 1
if count == 2:
    c1 = x1
    if k1 > max_prost:
      max_prost = k1
k2 = a * 100 + b * 10 + c
c2 = k2
count = 0
for i in range(1 , c2 + 1):
    if c2 % i == 0:
      count += 1
if count == 2:
    c2 = x
    if k2 > max_prost:
       max_prost = k2 
k3 = c * 10 + d
c3 = k3
count = 0
for i in range(1 , c3 + 1):
    if c3 % i == 0:
      count += 1
if count == 2:
    c3 = x
    if k3 > max_prost:
       max_prost = k3
k4 = b * 10 + c
c4= k4
count = 0
for i in range(1 , c4 + 1):
    if c4 % i == 0:
      count += 1
if count == 2:
    c4 = x
    if k4 > max_prost:
       max_prost = k4
k5 = a * 10 + b
c5 = k5
count = 0
for i in range(1 , c5 + 1):
    if c5 % i == 0:
      count += 1
if count == 2:
    c5 = x
    if k5> max_prost:
       max_prost = k5
k6 = a
c6 = k6
count = 0
for i in range(1 , c6 + 1):
    if c6 % i == 0:
      count += 1
if count == 2:
    c6 = x
    if k6 > max_prost:
       max_prost = k6
k7 = b
c7 = k7
count = 0
for i in range(1 , c7 + 1):
    if c7 % i == 0:
      count += 1
if count == 2:
    c7 = x
    if k7 > max_prost:
       max_prost = k7
k8 = c
c8 = k8
count = 0
for i in range(1 , c8 + 1):
    if c8 % i == 0:
      count += 1
if count == 2:
    c8 = x
    if k8 > max_prost:
       max_prost = k8
k9 = d
c9 = k9
count = 0
for i in range(1 , c9 + 1):
    if c9 % i == 0:
      count += 1
if count == 2:
    c9 = x
    if k9 > max_prost:
       max_prost = k9
k10 = a * 1000 + b * 100 + c * 10 + d
c10 = k10
count = 0
for i in range(1 ,  + 1):
    if c10 % i == 0:
      count += 1
if count == 2:
    c10 = x
    if k10 > max_prost:
       max_prost = k10
if len(str(x))!=4:
    max_prost = 0
if x<0:
    max_prost = 0
print(max_prost)

